package com.yunhe.tianhe.rentcars.service.system.impl;

import com.yunhe.tianhe.commons.dto.Pageable;
import com.yunhe.tianhe.commons.util.StringUtils;
import com.yunhe.tianhe.rentcars.dao.system.DeptDao;
import com.yunhe.tianhe.rentcars.entity.system.Dept;
import com.yunhe.tianhe.rentcars.service.system.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * # @Author: 贾波
 * # @Time: 2017-11-23-上午 10:29
 * # Description:
 */
@Service
public class DeptServiceImpl implements DeptService {
    private Pageable<Dept> pageable=new Pageable<>();
    @Autowired
    private DeptDao deptDao;

    public Long save(Dept dept) {
         deptDao.save(dept);
        return dept.getDeptId();
    }


    public void delete(Long id) {
        deptDao.delete(id);
    }


    public Long update(Dept dept) {
     return deptDao.update(dept);
    }


    public Dept findOne(Long id) {
        return deptDao.findOne(id);
    }


    public List<Dept> findList() {
        return deptDao.findList();
    }


    public Pageable<Dept> findPageList(Long offset, Long limit) {
       List<Dept> pageList = deptDao.findPageList(offset, limit);
        Long total = deptDao.pageCount();
        pageable.setTotal(total);
        pageable.setRows(pageList);
        return pageable;
    }

    public void deleteBatch(String ids) {
        if(StringUtils.notEmpty(ids)){
            String[] idArr = ids.split(",");
            for(String id : idArr) {
                this.delete(Long.valueOf(id));
            }
        }
    }

}
